<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="btn">按钮</button>
    <script src="./myajaxpromise2.js"></script>
    <script>
        btn.onclick = async function() {
            try{
                const res = await myAjax({
                url:'http://localhost:3000/test',
                data:{name:'zs',age:18},
                type:'Post',
                success(data){
                    console.log(data,'success成功');
                },
                complete() {
                    console.log('complete完成');
                },
                beforeSend() {
                    console.log('beforeSend之前');
                },
                error() {
                    console.log('error失败');
                }
            })
            console.log(res,'try中的promise成功');
            }
            catch(err) {
                console.log(err,'catch中的err');
            }
        }
    </script>
</body>
</html>